package com.kelvin.paopao.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kelvin.kelvinlib.imageloader.GlideUtil;
import com.kelvin.paopao.R;
import com.kelvin.paopao.api.responseBean.DateListModel;
import com.kelvin.paopao.module.main.date.datemain.MainDateFragment;

/**
 * Created by Administrator on 2017/5/16.
 */

public class MyAskDateAdapter extends BaseQuickAdapter<DateListModel, BaseViewHolder> {
    private Context context;

    public MyAskDateAdapter(Context context) {
        super(R.layout.recycler_my_ask_date_item);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, DateListModel item) {
        int type = Integer.parseInt(item.getOrdertype());
        if (type == MainDateFragment.TYPE_DATE_OTHER) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_other_selected);
            helper.setText(R.id.tv_date_title, "约人" + item.getItem_title());
        } else if (type == MainDateFragment.TYPE_DATE_SPORT) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_sport_selected);
            helper.setText(R.id.tv_date_title, "约人运动" + item.getItem_title());
        } else if (type == MainDateFragment.TYPE_DATE_EAT) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_eat_selected);
            helper.setText(R.id.tv_date_title, "约人吃饭" + item.getItem_title());
        } else if (type == MainDateFragment.TYPE_DATE_SING) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_sing_selected);
            helper.setText(R.id.tv_date_title, "约人唱歌" + item.getItem_title());
        } else if (type == MainDateFragment.TYPE_DATE_MOVIES) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_movie_selected);
            helper.setText(R.id.tv_date_title, "约人看电影" + item.getItem_title());
        } else if (type == MainDateFragment.TYPE_DATE_TRAVEL) {
            helper.setImageResource(R.id.iv_type, R.drawable.icon_main_list_travel_selected);
            helper.setText(R.id.tv_date_title, "约人去旅游" + item.getItem_title());
        }

        if (item.getImg1() == null && item.getImg2() == null && item.getImg3() == null) {
            helper.getView(R.id.ll_image_content).setVisibility(View.GONE);
        } else {

            GlideUtil.loadCommonBG(item.getImg1(), R.drawable.default_img, (ImageView)
                    helper.getView(R.id.iv_content1), context);
            GlideUtil.loadCommonBG(item.getImg2(), R.drawable.default_img, (ImageView)
                    helper.getView(R.id.iv_content2), context);
            GlideUtil.loadCommonBG(item.getImg3(), R.drawable.default_img, (ImageView)
                    helper.getView(R.id.iv_content3), context);
        }

        helper.setText(R.id.tv_date_content1, item.getOAddress());
        if (item.getIstip() == 0) {
            if (item.getOPayMode().equals("AA")) {
                helper.setText(R.id.tv_date_content2, "我们AA制");
            } else {
                helper.setText(R.id.tv_date_content2, "我买单");
            }
        } else {
            helper.setText(R.id.tv_date_content2, "有额外的酬劳");
        }

        helper.setText(R.id.tv_date_content3, item.getRemark());

        if (item.getStates() == 1) {
            helper.setText(R.id.text_status, "被选中");
            helper.setTextColor(R.id.text_status,
                    ContextCompat.getColor(mContext, android.R.color.holo_red_light));
        } else {
            helper.setText(R.id.text_status, "待确定");
            helper.setTextColor(R.id.text_status,
                    ContextCompat.getColor(mContext, R.color.text_color_hint));
        }

        if (TextUtils.isEmpty(item.getImg1()) && TextUtils.isEmpty(item.getImg2()) && TextUtils.isEmpty(item.getImg3())) {
            helper.getView(R.id.ll_image_content).setVisibility(View.GONE);
        } else {
            if (TextUtils.isEmpty(item.getImg1())) {
                helper.getView(R.id.iv_content1).setVisibility(View.GONE);
            }
            if (TextUtils.isEmpty(item.getImg2())) {
                helper.getView(R.id.iv_content2).setVisibility(View.GONE);
            }
            if (TextUtils.isEmpty(item.getImg3())) {
                helper.getView(R.id.iv_content3).setVisibility(View.GONE);
            }
        }
        helper.setText(R.id.tv_name, item.getUser_name());
        ImageView iv = helper.getView(R.id.iv_avatar);
        GlideUtil.loadImgCircle(item.getUser_headimg(), iv, context, R.drawable.default_img);

        helper.addOnClickListener(R.id.iv_content1).addOnClickListener(R.id.iv_content2)
                .addOnClickListener(R.id.iv_content3).addOnClickListener(R.id.iv_avatar);


    }
}